package model.baseElements;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import ru.yandex.qatools.htmlelements.element.HtmlElement;
import ru.yandex.qatools.htmlelements.loader.HtmlElementLoader;
import utils.PropertyLoader;

import java.util.concurrent.TimeUnit;

public abstract class BaseBlock extends HtmlElement {

    final Long WAIT_EXPLICITLY_DEFAULT_TIMEOUT
            = Long.valueOf(PropertyLoader.loadProperty("wait.explicitly.default"));
    final Long POLLING_EVERY_DEFAULT
            = Long.valueOf(PropertyLoader.loadProperty("polling.every.default"));

    protected WebDriver driver;
    protected Wait wait;

    public BaseBlock(WebDriver driver) {
        this.driver = driver;
        HtmlElementLoader.populatePageObject(this, driver);
        wait = new FluentWait(driver)
                .withTimeout(WAIT_EXPLICITLY_DEFAULT_TIMEOUT, TimeUnit.SECONDS)
                .pollingEvery(POLLING_EVERY_DEFAULT, TimeUnit.SECONDS);
    }

    protected void waitSleepBecauseIamToLazyToFindBetterSolution() throws InterruptedException {
        synchronized (this) {
            wait(2000);
        }
    }
}
